﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using OOAD_Project_Engine.Application.Services;
using OOAD_Project_Engine.Foundation.Interfaces;
using OOAD_Project_Engine.Domain.Entities;

namespace OOAD_Project_Editor.Domain.ManageSceneActions
{
    class CopyAction : ManageSceneAction
    {
        IEntity copyedEntity;
        public string NewName { get; private set; }
        public Entity newEntity { get; private set; }
        public CopyAction(ISceneService scene, IEntity entity, string newName)
            : base(scene)
        {
            this.ActionName = "copy";
            NewName = newName;
            copyedEntity = entity;
        }

        public CopyAction(ISceneService scene, IEntity entity) : this(scene, entity, entity.Name + "_copy") { }

        public override void DoAction()
        {
            string newEntityName = NewName;
            newEntity = new Entity(newEntityName);
            ICollection<IEntityComponent> entityComponents = copyedEntity;

            foreach (IEntityComponent c in entityComponents)
            {
                newEntity.Add(c.Clone() as IEntityComponent);
            }
        }

    }
}
